package escola.ifrn.edu.br;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
public abstract class AlunosDAOBean implements AlunosDAO {

	@PersistenceContext(unitName="escola")
	private EntityManager em;


	public AlunosDAOBean() {
	}

	@Override
	public void cadastrarAluno(Aluno aluno) {
		em.persist(aluno);
	}

	@SuppressWarnings("unchecked")
	public List<Aluno> getAlunos() {
		Query query = em.createNamedQuery("listaLivros");
		return query.getResultList();
	}

	@Override
	public Aluno getAlunoById(int id) {
		Query query = em.createNamedQuery("findAlunoById");
		return (Aluno) query.getSingleResult();
	}

}
